//
//  MZCollectedViewController.m
//  OurTourism
//
//  Created by 孟镇 on 15/12/5.
//  Copyright © 2015年 Devil_Coming. All rights reserved.
//

#import "MZCollectedViewController.h"
#import "MZCollectedCollectionViewCell.h"
#import "Header.h"
#import "YBStoryCollectionViewCell.h"
#import "YbManagementData.h"
@interface MZCollectedViewController () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (strong, nonatomic) IBOutlet UIButton *NoteBtn;
@property (strong, nonatomic) IBOutlet UIButton *photoBtn;
@property (strong, nonatomic) IBOutlet UIButton *modidiBtn;
@property (strong, nonatomic) IBOutlet UICollectionView *Collection;
@property (nonatomic, strong) YbManagementData *manageData;
@property (nonatomic, strong) NSMutableArray *storyArr;
@end

@implementation MZCollectedViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.navigationItem.title = @"游记收藏";
    
    
    [self getdata];
    
    self.NoteBtn.backgroundColor = [UIColor cyanColor];
    self.NoteBtn.layer.cornerRadius = 10;
    [self.NoteBtn addTarget:self action:@selector(noteAction) forControlEvents:UIControlEventTouchUpInside];
    self.photoBtn.layer.cornerRadius = 10;
    [self.photoBtn addTarget:self action:@selector(photoAction) forControlEvents:UIControlEventTouchUpInside];
    self.modidiBtn.layer.cornerRadius = 10;
    [self.modidiBtn addTarget:self action:@selector(mudidiAction) forControlEvents:UIControlEventTouchUpInside];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(WIDTH, HEIGTH  -94);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
     [self.Collection registerNib:[UINib nibWithNibName:NSStringFromClass([MZCollectedCollectionViewCell class]) bundle:nil] forCellWithReuseIdentifier:@"collectionItem"];
    
   
    
    [self.Collection registerClass:[YBStoryCollectionViewCell class] forCellWithReuseIdentifier:@"collectionItemone"];
    
    
    self.Collection.collectionViewLayout = layout;
    self.Collection.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.Collection.pagingEnabled = YES;
    self.Collection.showsHorizontalScrollIndicator = NO;
    self.Collection.showsVerticalScrollIndicator = NO;
}


- (void)getdata
{
    self.manageData = [YbManagementData shareInstance];
    [self.manageData openDB];
    self.storyArr = [self.manageData selectFromTable];
    
    
}

- (void)noteAction
{
    self.Collection.contentOffset = CGPointMake(0, 0);
    self.navigationItem.title = @"游记收藏";
    self.NoteBtn.backgroundColor = [UIColor cyanColor];
    self.photoBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.modidiBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
}
- (void)photoAction
{
    self.Collection.contentOffset = CGPointMake(WIDTH, 0);
    self.navigationItem.title = @"照片收藏";
    self.NoteBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.photoBtn.backgroundColor = [UIColor cyanColor];
    self.modidiBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
}
- (void)mudidiAction
{
    self.Collection.contentOffset = CGPointMake(WIDTH * 2, 0);
    self.navigationItem.title = @"目的地收藏";
    self.NoteBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.photoBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    self.modidiBtn.backgroundColor = [UIColor cyanColor];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.x == 0) {
        self.navigationItem.title = @"游记收藏";
        self.NoteBtn.backgroundColor = [UIColor cyanColor];
        self.photoBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        self.modidiBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    }
    if (scrollView.contentOffset.x == WIDTH) {
        self.navigationItem.title = @"照片收藏";
        self.NoteBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        self.photoBtn.backgroundColor = [UIColor cyanColor];
        self.modidiBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    }
    if (scrollView.contentOffset.x == WIDTH * 2) {
        self.navigationItem.title = @"目的地收藏";
        self.NoteBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        self.photoBtn.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        self.modidiBtn.backgroundColor = [UIColor cyanColor];
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.item == 0 ) {
        YBStoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionItemone" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        cell.arr = self.storyArr;
        return cell;
    }else if (indexPath.item == 1)
    {
    MZCollectedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionItem" forIndexPath:indexPath];
   cell.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
    return cell;
    }else
    {
        MZCollectedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionItem" forIndexPath:indexPath];
        cell.backgroundColor = [UIColor colorWithRed:250 / 255. green:246 / 255. blue:232 / 255. alpha:1];
        return cell;
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
